<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>JavaScript 实现高斯求和</title>
</head>
<script lang="JavaScript">
    function calc() {
        var a = Number(document.getElementById("para_a").value);
        var b = Number(document.getElementById("para_b").value);
        document.getElementById("sum").value = (a + b) * (b - a + 1) / 2;
    }
</script>

<body>
    <div>
        <p>
            求正整数
            <input type="text" id="para_a"> 到
            <input type="text" id="para_b"> 的和
        </p>
        <p><input type="button" value="计算" onclick="calc()"></p>
        <p>结果是：
            <input type="text" id="sum" readonly="readonly">
        </p>

    </div>
</body>

</html>